#include "mission_setup.sqf"
// The purpose of this script is to register mission objects to the server in order to generate all the needed needed scripts.
// This script has to be called in the initialization line of each object which has a role in the mission and should generate an action.
// It can also be called on the fly at runtime by passing the object as a parameter.
// NOTE: This should be called by the server only! If the object is generated locally, then you'll need to call this script through a custom server event.

// In the mission editor you'll add this:
// [this,"action",[arguments]] call "base\mission\register_object.sqf";

If (!IsServer) exitWith {};
If (typename _this != "ARRAY") exitWith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","Argument is not an array"];};
If (count _this <= 2) exitWith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","Not enough arguments"];};
If (typename (_this select 0) != "OBJECT") exitWith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","The first argument should be the object"];};
If (typename (_this select 1) != "STRING") exitWith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","The second argument should be a string for the Action"];};
If (typename (_this select 3) != "ARRAY") exitWith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","The third argument should be an array of Action parameters (can be empty array)"];};
// This will avoid problems if the VariableHolder is not yet initialized.
waituntil{!(isNil "JIP_HINV") AND !(isNil "d_mission_functions_compiled")};

private ["_object","_action","_arguments","_JIPH_MissionObjects"];

_object = _this select 0;
_action = _this select 1;
_arguments = _this select 2;

diag_log Format["(%1)[%2]: %3: %4 - %5(%6)",diag_tickTime,"register_object.sqf","Registering the object",(str _object),_action,count _arguments];
[_object, _action] call XfMissionSetAction;
[_object, _arguments] call XfMissionSetParameters;
_object call XfMissionAddObject;
diag_log Format["(%1)[%2]: %3",diag_tickTime,"register_object.sqf","Calling registering event"];
["d_all_mobject",_object] call XNetCallEvent;

